<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="s" uri="/struts-tags" %>
<script type="text/javascript"
        src="<%=request.getContextPath()%>/js/business/trail.js"></script>
<script type="text/javascript"
        src="<%=request.getContextPath()%>/js/business/book.js"></script>
<script type="text/javascript">
    var checkDetail = $("#checkDetailInput").val();

    if (checkDetail == "T") {
        $(function () {
            $(":text").attr("readOnly", "readOnly");
            $("#add").hide();
            $("#del").hide();
            $("#queren").hide();
// 		$("#li1Select").attr("onmousemove","this.setCapture();");
// 		$("#li1Select").attr("onmouseout","this.releaseCapture();");
            $("#li1Select").attr("onfocus", "this.blur();");
        });
    }
    $(function () {
        $("#soText").removeAttr("readOnly");
        var bookingState = $("#bookingState").val();
        if (bookingState == "BS05") {
            $("#soText").attr("readOnly", "readOnly");
            $("#button_so").hide();
            $("#soInfoSave").hide();
            $("#soInfoConfirm").hide();
        } else if (bookingState != "BS04") {
            $("#so").find("tr").eq(1).hide();
        }
    });
    /**
     * 保存上传so
     */
    function uploadSo() {
        var soDocumentId = $("#soid").val();
        var soText = $("#soText").val();
        if (soDocumentId == "" || soDocumentId == "undefined") {
            alert("请先上传SO文件!");
        } else if (soText == "") {
            alert("so号不能为空");
        } else {
            var bookingId1 = $("#bookingId").val();
            var data = "bookId=" + bookingId1 + "&so=" + soText;
            $.ajax({
                       url: "booking-updateSo",
                       cache: false,
                       async: false,
                       dataType: "json",
                       data: data,
                       success: function (data) {
                           alert($.parseJSON(data.msg).msg);
                       }
                   });
        }
    }

    /**
     * 确认完成订舱业务
     */
    function bookValidateFinish() {
        jw.confirm("请检查SO上传文件和SO号，是否完成订舱业务？", function () {
                       var soDocumentId = $("#soid").val();
                       var soText = $("#soText").val();
                       if (soDocumentId == "" || soDocumentId == "undefined") {
                           alert("请先上传SO文件!");
                       } else if (soText == "") {
                           alert("so号不能为空");
                       } else {
                           var bookingId1 = $("#bookingId").val();
                           var data = "bookId=" + bookingId1 + "&so=" + soText + "&isFinish=1";
                           $.ajax({
                                      url: "booking-updateSo",
                                      cache: false,
                                      async: false,
                                      dataType: "json",
                                      data: data,
                                      success: function (data) {
                                          alert($.parseJSON(data.msg).msg);
                                          if ($.parseJSON(data.msg).state == 1) {
                                              $("#button_so").hide();
                                              $("#soText").attr("disabled", true);
                                              $("#soInfoSave").hide();
                                              $("#soInfoConfirm").hide();
                                          }
                                      }
                                  });
                       }
                   },
                   function () {
                       return;
                   });
    }

    var book_gfDate_val = $("#book_gfDate").val();
    var book_gfDate = book_gfDate_val.substring(0, 10);
    $("#book_gfDate").val(book_gfDate);
    // var book_shipDate_val = $("#book_shipDate").val();
    // var book_shipDate = book_shipDate_val.substring(0,10);
    // $("#book_shipDate").val(book_shipDate);

    $(document).ready(function () {
        var port = new Array();
        $.ajax({
                   url: "../base/dropdown-port", async: false, success: function (data) {
                var all = data.results;
                $.each(all, function (i, n) {
                    port.push({id: n[1], label: n[0]});
                });
            }
               });
        var st_port_id = $("#stPort_book_id").val();
        var ar_port_id = $("#arPort_book_id").val();
        if (st_port_id != null || st_port_id != undefined || ar_port_id != null || ar_port_id
                                                                                   != undefined) {
            $.each(port, function (i, n) {
                if (n.id == st_port_id) {
                    $("#stPort_book").val(n.label);
                }
                if (n.id == ar_port_id) {
                    $("#arPort_book").val(n.label);
                }
            });
        }
    });


</script>
<style>
    #containers1 .li1 input {
        width: 30px;
    }
</style>
<div class="page_font">
    <input id="bookingState" type="hidden" name="book.bookingState" value="${book.bookingState }"/>
    <ul class="ul1">
        <!-- 		<li class="li1" style="font-size: 14px; padding-top: 4px;">订舱业务代理人：</li> -->
        <!-- 		<li class="li1"><input type="text" id="book_sup_id" -->
        <%-- 			name="book.supCompany.name" value="${book.supCompany.name}" /><input type="hidden" --%>
        <%-- 			id="book_sup" name="book.supCompany.id" value="${book.supCompany.id }" /></li> --%>
        <li class="li1 first_li">订舱业务代理人：</li>
        <li class="li1"><input type="text" id="book_boat_id"
                               name="book.supCompany.name" value="${book.supCompany.name }"/><input
                type="hidden" id="book_boat" name="book.supCompany.id"
                value="${book.supCompany.id }"/></li>
    </ul>
    <table>
        <tr>
            <td class="first_li">货物信息填写：</td>
        </tr>
    </table>
    <div id="newGoods" class="bizMsg">
        <div>
            <ul>
                <li class="li1">货物名称：</li>
                <li class="li1"><input type="text" id="goodsName"/></li>
                <li class="li1 li1_space">每柜毛重：</li>
                <li class="li1"><input type="text" id="weight"/>kg</li>
                <li class="li1 li1_space">体积：</li>
                <li class="li1"><input type="text" id="volume"/>m³</li>
            </ul>
            <div class="clean"></div>
        </div>
        <div id="book">
            <input value="${book.id}" type="hidden" name="book.id" id="bookingId"/>
            <input value="${checkDetail}" type="hidden" id="checkDetailInput"/>
            <ul>
                <li class="li1 li1_Special">柜量：</li>
            </ul>
            <ul id="containers1">
                <li class="li1"><span class='containerType1'><input
                        id="ct_num1" type="text" class="ct_num1"/><input id="ct_size1"
                                                                         type="text"
                                                                         class="ct_size1"/><input
                        id="ct_type1" type="text"
                        class="ct_type1"/></span></li>
                <li><input type="button" onclick="addCtbookType()" value="添加柜型" id="add"/>
                    <input type="button" onclick="delCtBookType();" id="delbookType" id="del"
                           value="删除柜型">
                    <!--<input type="button" onclick="showTrailInfo();" value="确认柜量" /></li>-->
                    <input type="hidden" id="isModify"/> <input type="hidden"
                                                                id="temp_goodsId"/> <input
                            type="button" value="确认货物"
                            id="queren"
                            onclick="confirm();"/>
                    <input id="clearPkInput" value="${clearPk}" type="hidden"/>
            </ul>
        </div>
    </div>

    <table>
        <tr>
            <td class="first_li">货物列表：</td>
        </tr>
    </table>
    <table class="dataTB dataTB_Individual booking_dataTB_Individual "
           id="goodsList">

        <tr>
            <td class="booking_titleTD" lang="name">货物名称</td>
            <td class="booking_titleTD" lang="gweight">每柜毛重</td>
            <td class="booking_titleTD" lang="volume">体积</td>
            <td class="booking_titleTD" lang="ctNumType">柜型</td>
            <td style="display: none;" lang="id"></td>
        </tr>
        <s:iterator value="book.goodses" status="st">
            <tr id="goodsList_<s:property value="#st.index" />"
                onclick="edit(this);" class="pointer">
                <td><s:property value="name"/></td>
                <td><s:property value="gweight"/></td>
                <td><s:property value="volume"/></td>
                <td><s:property value="ctNumType"/></td>
                <td style="display: none;"><s:property value="id"/></td>
            </tr>
        </s:iterator>
    </table>
    <br/>
    <!-- 	<table> -->
    <!-- 		<tr> -->
    <!-- 			<td class="first_li">收货人信息：</td> -->
    <!-- 		</tr> -->
    <!-- 	</table> -->
    <!-- 	<div class="bizMsg"> -->
    <!-- 		<div> -->
    <!-- 			<ul> -->
    <!-- 				<li class="li1">收货公司名称：</li> -->
    <!-- 				<li class="li1"><input id="arr_company" type="text" -->
    <%-- 					name="book.consignee.company" value="${ book.consignee.company}" /><input --%>
    <!-- 					type="hidden" id="arr_company_id" name="book.consignee.id" -->
    <%-- 					value="${book.consignee.id }" /></li> --%>
    <!-- 				<li class="li1 li1_space">联系人：</li> -->
    <!-- 				<li class="li1"><input type="text" id="arr_con_name" -->
    <%-- 					name="book.consignee.name" value="${book.consignee.name }" /></li> --%>
    <!-- 				<li class="li1 li1_space">联系电话：</li> -->
    <!-- 				<li class="li1"><input type="text" id="arr_con_phone" -->
    <%-- 					name="book.consignee.phone" value="${book.consignee.phone }" /></li> --%>
    <!-- 			</ul> -->
    <!-- 		</div> -->
    <!-- 	</div> -->
    <table>
        <tr>
            <td class="first_li" style="padding-top: 10px;">托运信息：</td>
        </tr>
    </table>
    <div class="bizMsg">
        <div>
            <table>
                <ul class="ul1">
                    <!-- 			<li class="li1">订舱业务代理人：</li> -->
                    <!-- 			<li class="li1"><input type="text" id="book_boat_id" -->
                    <%-- 			name="book.supCompany.name" value="${book.supCompany.name }" /><input --%>
                    <!-- 			type="hidden" id="book_boat" name="book.supCompany.id" -->
                    <%-- 			value="${book.supCompany.id }" /></li> --%>
                    <tr>
                        <td>
                            <li class="li1 li1_space" style="float:right;">大船公司：</li>
                        </td>
                        <td>
                            <li class="li1"><input type="text" id="book_ship_id"
                                                   name="book.shipping.name"
                                                   value="${book.shipping.name }"/><input
                                    type="hidden" id="book_ship" name="book.shipping.id"
                                    value="${book.shipping.id }"/></li>
                        </td>
                        <td>
                            <li class="li1 li1_space">成交方式：</li>
                        </td>
                        <td>
                            <li class="li1"><input type="text" id="businessType"
                                                   name="book.businessType"
                                                   value="${book.businessType }"/>
                        </td>
                        <!-- 			</ul> -->
                        <!-- 		</div> -->
                        <!-- 		<div> -->
                        <!-- 			<ul class="ul1"> -->
                        <td>
                            <li class="li1"
                                style="padding-left: 42px; letter-spacing: 2px;float:right;">起运港：
                            </li>
                        </td>
                        <td>
                            <li class="li1"><input type="text" id="stPort_book" value=""/><input
                                    type="hidden"
                                    name="book.stPort"
                                    id="stPort_book_id"
                                    value="<s:property value='book.stPort' />"/>
                            </li>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <li class="li1" style="padding-left: 42px; letter-spacing: 2px;">目的港：
                            </li>
                        </td>
                        <td>
                            <li class="li1"><input type="text" id="arPort_book" value=""/><input
                                    type="hidden"
                                    name="book.arPort"
                                    id="arPort_book_id"
                                    value="<s:property value='book.arPort' />"/>
                            </li>
                        </td>
                        <td>
                            <li class="li1 li1_space">船期要求：</li>
                        </td>
                        <td>
                            <li class="li1"><input type="text" id="book_shipDate"
                                                   name="book.shipDate" value="${book.shipDate }"/>
                            </li>
                        </td>
                        <!-- 			</ul> -->
                        <!-- 		</div> -->
                        <!-- 		<div> -->
                        <!-- 			<ul class="ul1"> -->
                        <td>
                            <li class="li1"
                                style="padding-left: 42px; letter-spacing: 2px; float:right;">总柜型柜量：
                            </li>
                        </td>
                        <td>
                            <li class="li1">
                                <!-- 					<input style="width: 96px;" type="text" -->
                                <!-- 						readonly="readonly" name="book.ctNumType" -->
                                <%-- 						value="${book.ctNumType }" />  <span class='containerType2'> --%>
                                <input id="bookTotalType"
                                       name="book.ctNumType" type="text" readonly="readonly"
                                       class='containerType2'
                                       value="${book.ctNumType}"/>
                                <%-- 				</span> --%>
                            </li>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <li class="li1 li1_space" style="padding-left: 3px;float:right;">合作价格：
                            </li>
                        </td>
                        <td>
                            <li class="li1"><input type="text" name="book.price"
                                                   value="${book.price }"/></li>
                        </td>
                        <td>
                            <li class="li1 li1_space" style="padding-left: 22px;">备注：</li>
                        </td>
                        <td>
                            <li class="li1"><input type="text" name="book.remark"
                                                   value="${book.remark }"/></li>
                        </td>
                        <!-- 			</ul> -->
                        <!-- 		</div> -->
                        <!-- 		<div> -->
                        <!-- 			<ul class="ul1"> -->
                        <td>
                            <li class="li1 li1_space"
                                style="padding-left: 42px; letter-spacing: 2px;">货好时间：
                            </li>
                        </td>
                        <td>
                            <li class="li1"><input type="text" id="book_gfDate"
                                                   name="book.gfDate" value="${book.gfDate }"/></li>
                        </td>
                    </tr>
                </ul>
            </table>
        </div>
    </div>
    <div class="clean"></div>
    <div id="book_input" style="display: none;"></div>
    <br/>
    <div id="so">
        <table>
            <tr>
                <td class="first_li">SO信息：</td>
            </tr>
            <tr>
                <td><s:if test="book.soDoc!=null"><s:property
                        value="book.soDoc.name"/>&nbsp;&nbsp;<%-- <input type="button" value="点击下载SO文件" onclick="javascript:window.location.href='download?attachment.id=<s:property value="book.soDoc.id"/>'"> --%>
                </s:if><s:else>上传</s:else></td>
                <td><input id="button_so" type="button" value="选择文件" onclick="upload();"/></td>
                <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
                <td>so号：</td>
                <td><input id="soText" type="text" value="<s:property value='book.so'/>"></td>
                <td><input id="soInfoSave" type="button" onclick="uploadSo()" value="保存"/></td>
                <td><input id="soInfoConfirm" type="button" onclick="bookValidateFinish()"
                           value="完成"/></td>
            </tr>
        </table>
    </div>
    <div id="upload_so" style="display:none;">
        SO信息：<span id="soValue"></span><input name="book.soDoc.id"
                                              value="<s:property value="book.soDoc.id" />"
                                              id="soid" style="display:none;"/>
    </div>
    <div id="dialog001" style="display:none">
        <s:form id="uploadForm" action="attach-upload?type=booking" enctype="multipart/form-data"
                method="POST">
            <s:file label="选择文件" name="attach"></s:file>
            <s:set name="book.id" value="book.id"></s:set>
            <s:hidden name="bookid" value="%{book.id}"></s:hidden>
            <s:submit value="上传"></s:submit>
        </s:form>
    </div>
    <!-- 	<fieldset><legend>操作选项</legend> -->
    <!-- <button ID="trailVpassBtn" onclick="validatePass();">审核</button> -->
    <!-- <button ID="trailVrejectBtn" onclick="validateReject();">驳回业务</button> -->
    <!-- </fieldset> -->
</div>
<script type="text/javascript">

    /**
     *审核
     */

    function validatePass() {
        var id = "${book.id}";

        var iddata = "id=" + id + "&opType=tgsh";
        $.ajax({
                   url: "booking-checkValidatePass",
                   dataType: "json",
                   data: iddata,
                   success: function (data) {
                       if (!data) {
                           return;
                       }
                       var msg = data.msg ? $.parseJSON(data.msg) : "";
                       if (msg.state == 1) {
                           jw.confirm("确定要该业务通过审核?", function () {
                                          $.ajax({
                                                     url: "booking-validatePass",
                                                     dataType: "json",
                                                     data: iddata,
                                                     success: function (data) {
                                                         jw.alert(msg.msg,
                                                                  {
                                                                      onOk: function () {
                                                                          window.location.href =
                                                                                  "booking-listForSupToValidate";
                                                                      }
                                                                  });
                                                     }
                                                 });
                                      },
                                      function () {
                                          return;
                                      });
                       }
                       else if (msg !== undefined && msg != "" && msg.state == 0) {
                           jw.alert("只有处于待审核状态的业务才可以进行审核操作。");
                       }
                       else {
                           jw.alert(msg.msg);
                       }
                   }
               });
    }
    /*
     * 驳回
     */
    function validateReject() {
        var id = "${book.id}";

        var iddata = "id=" + id + "&opType=bh";
        $.ajax({
                   url: "booking-checkValidatePass",
                   dataType: "json",
                   data: iddata,
                   success: function (data) {
                       if (!data) {
                           return;
                       }
                       var msg = data.msg? $.parseJSON(data.msg) : "";
                       if (msg.state ==1) {
//	 				jw.confirm("确定要驳回该业务?",function(){
                           jw.dialog({
                                         iframe: '../business/rejectContent-reject?id=' + id
                                                 + "&type=3",
                                         title: "驳回",
                                         iframeFetchTitle: false,
                                         width: 500,
                                         height: 150
                                     });
//	 					$.ajax({
//	 						url : "booking-validateReject",
//	 						dataType : "json",
//	 						data : iddata,
//	 						success : function(data) {
//	 							jw.alert($.parseJSON(data.msg).msg,
//	 									{
//	 										onOk: function() {
//	 											window.location.href="booking-listForSupToValidate";
//	 										}
//	 									});
//	 						}
//	 					});
//	 				},
//	 				function(){return;});
                       }
                       else if (msg !== undefined && msg != "" && msg.state == 0) {
                           jw.alert("只有处于待审核状态的业务才可以进行驳回业务操作。");
                       }
                       else {
                           jw.alert(msg.msg);
                       }
                   }
               });
    }
</script>
